home *** CD-ROM | disk | FTP | other *** search
/ Programming a Multiplayer FPS in DirectX / Programming a Multiplayer FPS in DirectX (Companion CD).iso / DirectX / dxsdk_oct2004.exe / dxsdk.exe / Documentation / DirectX9 / directplay.chm / code / lookup.js < prev    next >
Encoding:
Text File  |  2004-09-27  |  47.9 KB  |  1,938 lines

  1. <![CDATA[
  2. // LOOKUP.JS code BEGIN  //at
  3. var gsExt = ".asp";
  4. var gaMapLang2SubNode = {'cpp' : 'iface', 'vb' : 'object'};
  5. var gaMapScope = {'cpp' : '::', 'vb' : '.'};
  6. var gaMapAttr = {'cpp' : 'iid'}; // allows the author to resolve an ambiguous reference to a shared member
  7. var gaMapAuto = {'cpp' : 'autoiid'}; // pointing to a shared topic we need to auto-resolve since the links differs depending on context
  8. var gaMapPNRN = {'rn' : 'runtime name', 'pn' : 'persistent name', 'name' : 'name'};
  9. var gaDLangMap = {'self' : 'devlang', 'ext' : 'dlang'}; // handle name difference: metadata/devlang vs. targ/dlang
  10. var aFlagAttrMap = {'cpp' : 'name', 'scr' : 'value', 'vb' : 'name'}; // map devlang to appropriate attribute in a flag
  11.  
  12. // List of regular expressions for URLs that are known to be Microsoft sites
  13. var gaMSSiteREs = [ /microsoft\.com/i, /msn\.com/i, /gotdotnet\.com/i, /biztalk\.org/i, /bcentral\.com/i, /zone\.com/i ];
  14.  
  15. // BUGBUG: Hardcoded extension map.
  16. var gaExtMap = {'asp' : 'htm'};
  17.  
  18. var NODE_TEXT = 3;
  19.  
  20. // simple source object; use an instance in place of an xref node when performing a lookup
  21. function CSimpleSrc(sRID, sCurLang)
  22. {
  23.   this.rid = sRID;
  24.   this.devlang = sCurLang;
  25. }
  26.  
  27. // sets a flag indicating the object is a self reference
  28. CSimpleSrc.prototype.SetSelf = function(b)
  29. {
  30.   this.self = b;
  31. }
  32.  
  33. CSimpleSrc.prototype.IsSelfReference = function()
  34. {
  35.   return (this.self ? true : false);
  36. }
  37.  
  38. /////////////////////////////////////////////////////////////
  39.  
  40. // encapsulates an a cached target node
  41. function CCacheItem(oTNode, iRefCount)
  42. {
  43.   Node2Object(oTNode, this, "_");
  44.  
  45.   this._targetNode = oTNode;
  46.   this._cRefs = iRefCount; // number of references to this target
  47. }
  48.  
  49. /////////////////////////////////////////////////////////////
  50.  
  51. function CLookup(oCtx)
  52. {
  53.   this._oCtx = oCtx;
  54.   this._error = "";
  55.   this._fBadDataSrc = false;
  56.   this._cache = new Array();
  57.   this._aTLAs = new Array();  //at
  58.   this._sTLA = "";            //at
  59.   this._bTLACap = false;      //at
  60.   this._bTLAPlural = false;   //at
  61.   this._oAcronym = null;      //at
  62. }
  63.  
  64. CLookup.prototype.ClearError = function()
  65. {
  66.   this._error = "";
  67. }
  68.  
  69. // Attempt to pull the cached item from the local hash, or cache it
  70. CLookup.prototype.RetrieveCachedItem = function(sRID, bNoIncRefs)
  71. {
  72.   var oCacheItem = this._cache[sRID];
  73.   if (oCacheItem)
  74.   {
  75.     if (!bNoIncRefs)
  76.     {
  77.       oCacheItem._cRefs++
  78.     }
  79.   }
  80.   else
  81.   {
  82.     oCacheItem = this.CacheItem(sRID, bNoIncRefs);
  83.   }
  84.  
  85.   return oCacheItem;
  86. }
  87.  
  88. // Lookup the specified rid in the store.
  89. //at *** Rewritten for LuCache.
  90. CLookup.prototype.RetrieveTarget = function(sRID)
  91. {
  92.   var bOk = false;
  93.   var sTargXML = null;
  94.   var sTPath = this._oCtx._sDrive + this._oCtx.GetPathOf("targets");
  95.   var oTNode = null;
  96.   var oData = null;
  97.   var bLuCache = this._oCtx.CacheLookups();
  98.  
  99.   oData = this.EnsureData(bLuCache);
  100.   bLuCache = this._oCtx.CacheLookups();
  101.  
  102.   if (bLuCache && oData)
  103.   {
  104.     // Try to use the LuCache Lookup Cache.
  105.     try
  106.     {
  107.       // Call LuCache to lookup the RID and get back the node-xml.
  108.       sTargXML = oData.LookupId(sRID, sTPath);
  109.     }
  110.     catch(e)
  111.     {
  112.       this._error = "LuCache failure." + e.description;
  113.       sTargXML = null;
  114.     }
  115.     if (sTargXML)
  116.     {
  117.       var oTDom = this._oCtx._oTDom;
  118.  
  119.       // Now use "mini-dom" node to load node-xml and get a node.
  120.       oTDom.async = false;
  121.       oTDom.loadXML(sTargXML);
  122.       oTNode = oTDom.documentElement;
  123.       if (oTNode)
  124.         bOk = true;
  125.       else
  126.         this._error = "cannot load target node.";
  127.     }
  128.     else
  129.       this._error = "rid not found (" + sRID + ").";
  130.   }
  131.   else
  132.   {
  133.     // Try to use a loaded DOM for lookups.
  134.     if (bLuCache && !oData)
  135.       oData = this.EnsureData(false);
  136.     if (oData)
  137.     {
  138.       // oTNode = oData.selectSingleNode("id('" + sRID + "')");
  139.       // Use faster nodeFromID.
  140.       oTNode = oData.nodeFromID(sRID);
  141.       if (oTNode)
  142.         bOk = true;
  143.       else
  144.         this._error = "rid not found (" + sRID + ").";
  145.     }
  146.     else
  147.       this._error = "cannot create access to targets.";
  148.   }
  149.  
  150.   if (!bOk)
  151.     oTNode = null;
  152.  
  153.   return oTNode;
  154. }
  155.  
  156. // Get topicinfo node from topinfo.xml. //at
  157. CLookup.prototype.RetrieveTopicInfo = function(sID)
  158. {
  159.   var bOk = false;
  160.   var sTIXML = null;
  161.   var sTIPath = this._oCtx._sDrive + this._oCtx.GetPathOf("topinfo");
  162.   var oTINode = null;
  163.   var oData = null;
  164.   var bLuCache = this._oCtx.CacheLookups();
  165.  
  166.   oData = this.EnsureTIData(bLuCache);
  167.   bLuCache = this._oCtx.CacheLookups();
  168.  
  169.   if (bLuCache && oData)
  170.   {
  171.     // Try to use the LuCache Lookup Cache.
  172.     try
  173.     {
  174.       // Call LuCache to lookup the RID and get back the node-xml.
  175.       sTIXML = oData.LookupId(sID, sTIPath);
  176.       if (!sTIXML)
  177.         this._error = "id not found (" + sID + ").";
  178.     }
  179.     catch(e)
  180.     {
  181.       this._error = "LuCache failure. " + e.description;
  182.       sTIXML = null;
  183.     }
  184.     if (sTIXML)
  185.     {
  186.       var oTIDom = this._oCtx._oTDom;
  187.  
  188.       // Now use "mini-dom" node to load node-xml and get a node.
  189.       oTIDom.async = false;
  190.       oTIDom.loadXML(sTIXML);
  191.       oTINode = oTIDom.documentElement;
  192.       if (oTINode)
  193.         bOk = true;
  194.       else
  195.         this._error = "cannot load topic info node.";
  196.     }
  197.   }
  198.   else
  199.   {
  200.     // Try to use a loaded DOM for lookups.
  201.     if (bLuCache && !oData)
  202.       oData = this.EnsureTIData(false);
  203.     if (oData)
  204.     {
  205.       // oTNode = oData.selectSingleNode("id('" + sID + "')");
  206.       // Use faster nodeFromID.
  207.       oTINode = oData.nodeFromID(sID);
  208.       if (oTINode)
  209.         bOk = true;
  210.       else
  211.         this._error = "id not found (" + sID + ").";
  212.     }
  213.     else
  214.     {
  215.       if (!this._error)
  216.         this._error = "cannot create access to topic info.";
  217.     }
  218.   }
  219.  
  220.   if (!bOk)
  221.     oTINode = null;
  222.  
  223.   return oTINode;
  224. }
  225.  
  226. // Get acronym node (ie, using TLA rid) from acronyms.xml. //at
  227. CLookup.prototype.RetrieveAcronym = function(sID)
  228. {
  229.   var bOk = false;
  230.   var sAcXML = null;
  231.   var sAcPath = this._oCtx._sDrive + this._oCtx.GetPathOf("acronyms");
  232.   var sAcDtdPath = this._oCtx._sDrive + this._oCtx.GetPathOf("acronymsdtd");
  233.   var oAcNode = null;
  234.   var oData = null;
  235.   var bLuCache = this._oCtx.CacheLookups();
  236.  
  237.   oData = this.EnsureAcData(bLuCache);
  238.   bLuCache = this._oCtx.CacheLookups();
  239.  
  240.   if (bLuCache && oData)
  241.   {
  242.     // Try to use the LuCache Lookup Cache.
  243.     try
  244.     {
  245.       // Call LuCache to lookup the RID and get back the node-xml.
  246.       sAcXML = oData.LookupId(sID, sAcPath);
  247.       if (!sAcXML)
  248.         this._error = "id not found (" + sID + ").";
  249.     }
  250.     catch(e)
  251.     {
  252.       this._error = "LuCache failure. " + e.description;
  253.       sAcXML = null;
  254.     }
  255.     if (sAcXML)
  256.     {
  257.       var oAcDom = this._oCtx._oTDom;
  258.       var sXML = '<!DOCTYPE acronym SYSTEM "'+sAcDtdPath+'" []>'+sAcXML;
  259.  
  260.       // Now use "mini-dom" node to load node-xml and get a node.
  261.       oAcDom.async = false;
  262.       oAcDom.loadXML(sXML);
  263.       oAcNode = oAcDom.documentElement;
  264.       if (oAcNode)
  265.         bOk = true;
  266.       else
  267.         this._error = "cannot load acronym node.";
  268.     }
  269.   }
  270.   else
  271.   {
  272.     // Try to use a loaded DOM for lookups.
  273.     if (bLuCache && !oData)
  274.       oData = this.EnsureAcData(false);
  275.     if (oData)
  276.     {
  277.       // oAcNode = oData.selectSingleNode("id('" + sID + "')");
  278.       // oAcNode = oData.selectSingleNode("/acroot/inetsdk:acronyms/acronym[@id='"+sID+"']");
  279.       // Use faster nodeFromID.
  280.       oAcNode = oData.nodeFromID(sID);
  281.       if (oAcNode)
  282.         bOk = true;
  283.       else
  284.         this._error = "id not found (" + sID + ").";
  285.     }
  286.     else
  287.     {
  288.       if (!this._error)
  289.         this._error = "cannot create access to acronyms.";
  290.     }
  291.   }
  292.  
  293.   if (oAcNode && oAcNode.getAttribute("deprecated"))
  294.     bOk = false;
  295.  
  296.   if (!bOk)
  297.     oAcNode = null;
  298.  
  299.   return oAcNode;
  300. }
  301.  
  302. // Resets firsttime status for all TLAs encountered so far in the
  303. // page transformation. Use with care. //at
  304. CLookup.prototype.ResetTLA = function()
  305. {
  306.   var i = 0;
  307.  
  308.   if (this._aTLAs)
  309.   {
  310.     delete this._aTLAs;
  311.     this._aTLAs = new Array();  //at
  312.   }
  313.  
  314.   return false;
  315. }
  316.  
  317. // Determine if the authored TLA is in acronyms.xml.
  318. // Called directly from XSL. //at
  319. CLookup.prototype.IsTLA = function(oTLA)
  320. {
  321.   var bYes = false;
  322.   var sRid = null;
  323.   var oAc = null;
  324.   var sVal = "";
  325.  
  326.   this._sTLA = "";
  327.   this._bTLACap = false;
  328.   this._bTLAPlural = false;
  329.   this._oAcronym = null;
  330.  
  331.   if (oTLA)
  332.   {
  333.     sRid = oTLA.getAttribute("rid");
  334.     if (sRid)
  335.     {
  336.       oAc = this.RetrieveAcronym(sRid);
  337.       if (oAc)
  338.       {
  339.         sVal = oTLA.getAttribute("initcap");
  340.         if (sVal)
  341.           this._bTLACap = true;
  342.  
  343.         sVal = oTLA.getAttribute("plural");
  344.         if (sVal)
  345.           this._bTLAPlural = true;
  346.  
  347.         this._oAcronym = oAc;
  348.         bYes = true;
  349.       }
  350.     }
  351.   }
  352.  
  353.   return bYes;
  354. }
  355.  
  356. // In the current document, determine if this node is the first
  357. // TLA using its associated ID (rid). Use associative array to
  358. // remember the TLA Rids encountered.  //at
  359. CLookup.prototype.IsFirstTLA = function(sRid)
  360. {
  361.   var bYes = false;
  362.   var bFound = false;
  363.  
  364.   if (sRid)
  365.   {
  366.     bFound = this._aTLAs[sRid];
  367.     if (!bFound)
  368.     {
  369.       this._aTLAs[sRid] = true;
  370.       bYes = true;
  371.     }
  372.   }
  373.  
  374.   return bYes;
  375. }
  376.  
  377. // Workhorse internal function to build the TLA substitution
  378. // string when nested TLA strings are being appended.
  379. // Note the indirect recursive call relation between this
  380. // function and MakeTLA. //at
  381. CLookup.prototype.NestTLA = function(oAcNode)
  382. {
  383.   var bOk = false;
  384.   var oAcNested = null;
  385.   var aNested = null;
  386.   var oNested = null;
  387.   var sRidNested = "";
  388.   var sText = "";
  389.   var sChar = "";
  390.   var i = 0;
  391.  
  392.   if (oAcNode)
  393.   {
  394.     aNested = oAcNode.selectNodes("tla");
  395.     if (aNested && aNested.length>0)
  396.     {
  397.       for(i=0; i<aNested.length; i++)
  398.       {
  399.         oNested = aNested[i];
  400.         if (oNested)
  401.         {
  402.           sRidNested = oNested.getAttribute("rid");
  403.           if (sRidNested)
  404.           {
  405.             oAcNested = this.RetrieveAcronym(sRidNested);
  406.             bOk = this.MakeTLA(oAcNested);
  407.           }
  408.         }
  409.       }
  410.  
  411.       sText = oAcNode.text;
  412.       sChar = sText.substr(0,1);
  413.       sChar = sChar.toLowerCase();
  414.       switch (sChar)
  415.       {
  416.         case ".":
  417.           sText = sText.toLowerCase();
  418.           if (sText == ".net")
  419.             this._sTLA += " "+oAcNode.text;
  420.           else
  421.             this._sTLA += oAcNode.text;
  422.           break;
  423.         case " ":
  424.         case ",":
  425.         case ":":
  426.         case ";":
  427.           this._sTLA += oAcNode.text;
  428.           break;
  429.         default:
  430.           this._sTLA += " "+oAcNode.text;
  431.           break;
  432.       }
  433.     }
  434.     else
  435.       this._sTLA += oAcNode.text;
  436.   }
  437.  
  438.   return bOk;
  439. }
  440.  
  441. // Workhorse internal recursive function that builds the substitution
  442. // string for a TLA.  It determines if the Acronym node (oAc) should
  443. // be expanded to its primary or secondary representation.
  444. // According to MSTE, the first instance of a trademark (TM) or
  445. // registered trademark (R) name should include the trademark marking.
  446. // Editorially, this should also mean that the first use of a
  447. // product name within a topic should be referenced by a TLA that
  448. // has the proper marking.  Subsequent instances of the trademarked
  449. // names within the same topic should not show the trademark
  450. // marking. Note the indirect recursive call relation between this
  451. // function and NestTLA. //at
  452. CLookup.prototype.MakeTLA = function(oAc)
  453. {
  454.   var bOk = false;
  455.   var bFirst = true;
  456.   var sRid = "";
  457.   var oPrimary = null;
  458.   var oSecondary = null;
  459.  
  460.   if (oAc)
  461.   {
  462.     oSecondary = oAc.selectSingleNode("secondary");
  463.     oPrimary = oAc.selectSingleNode("primary");
  464.     sRid = oAc.getAttribute("id");
  465.     bFirst = this.IsFirstTLA(sRid);
  466.     if (bFirst)
  467.       bOk = this.NestTLA(oPrimary);
  468.     else
  469.     {
  470.       if (oSecondary)
  471.         bOk = this.NestTLA(oSecondary);
  472.       else
  473.         bOk = this.NestTLA(oPrimary);
  474.     }
  475.   }
  476.  
  477.   return bOk;
  478. }
  479.  
  480. //at Make Plural TLA.
  481. CLookup.prototype.MakeTLAP = function(oAc)
  482. {
  483.   var bOk = false;
  484.   var bFirst = true;
  485.   var sRid = "";
  486.   var oPrimary = null;
  487.   var oSecondary = null;
  488.  
  489.   if (oAc)
  490.   {
  491.     oSecondary = oAc.selectSingleNode("secondaryp");
  492.     oPrimary = oAc.selectSingleNode("primaryp");
  493.     sRid = oAc.getAttribute("id");
  494.     bFirst = this.IsFirstTLA(sRid);
  495.     if (bFirst)
  496.       this.NestTLA(oPrimary);
  497.     else
  498.     {
  499.       if (oSecondary)
  500.         this.NestTLA(oSecondary);
  501.       else
  502.         this.NestTLA(oPrimary);
  503.     }
  504.     bOk = true;
  505.   }
  506.  
  507.   return bOk;
  508. }
  509.  
  510. // Just return the TLA's substitution string.
  511. // Must be called immediately after IsTLA has been called.
  512. // Called internally or directly from XSL. //at
  513. CLookup.prototype.GetTLA = function(oAcronym)
  514. {
  515.   var sChar = "";
  516.   var sRest = "";
  517.   var sRet = "";
  518.   var sTLA = "";
  519.   var nLen = 0;
  520.   var oAc = null;
  521.   var bPlDone = false;
  522.  
  523.   if (oAcronym)
  524.   {
  525.     this._sTLA = "";
  526.     oAc = oAcronym;
  527.   }
  528.   else
  529.     oAc = this._oAcronym;
  530.  
  531.   if (this._bTLAPlural && oAc.selectSingleNode("primaryp"))
  532.     bPlDone = this.MakeTLAP(oAc);
  533.   else
  534.     this.MakeTLA(oAc);
  535.  
  536.   if (this._bTLACap)
  537.   {
  538.     sTLA = this._sTLA;
  539.     sChar = sTLA.substr(0,1);
  540.     sRest = sTLA.substr(1);
  541.     this._sTLA = sChar.toUpperCase() + sRest;
  542.   }
  543.  
  544.   if (!bPlDone && this._bTLAPlural)
  545.   {
  546.     sTLA = this._sTLA;
  547.     nLen = sTLA.length;
  548.     sChar = sTLA.substr(nLen-1,1);
  549.     sChar = sChar.toLowerCase();
  550.     switch (sChar)
  551.     {
  552.       case "x":
  553.       case "s":
  554.         sRest = "es";
  555.         break;
  556.       default:
  557.         sRest = "s";
  558.         break;
  559.     }
  560.     this._sTLA = sTLA + sRest;
  561.   }
  562.  
  563.   return this._sTLA;
  564. }
  565.  
  566. // Find TLA and return its substitution string.
  567. // Called directly from XSL. //at
  568. CLookup.prototype.TLA = function(sRid)
  569. {
  570.   var sTLA = "";
  571.   var oAc = null;
  572.  
  573.   this._sTLA = "";
  574.   this._oAcronym = null;
  575.   this._bTLACap = false;
  576.   this._bTLAPlural = false;
  577.  
  578.   if (sRid)
  579.   {
  580.     oAc = this.RetrieveAcronym(sRid);
  581.     if (oAc)
  582.     {
  583.       this._oAcronym = oAc;
  584.       sTLA = this.GetTLA();
  585.     }
  586.   }
  587.  
  588.   return sTLA;
  589. }
  590.  
  591.  
  592. // convert the attribs of the target node to properties of a
  593. // JS object and store the target node in hash.
  594. CLookup.prototype.CacheItem = function(sRID, bNoIncRefs)
  595. {
  596.   var oTNode;
  597.   if (!(oTNode = this.RetrieveTarget(sRID)))
  598.   {
  599.     return null;
  600.   }
  601.  
  602.   return new CCacheItem(oTNode, (bNoIncRefs ? 0 : 1));
  603.   //return (this._cache[sRID] = new CCacheItem(oTNode, (bNoIncRefs ? 0 : 1)));
  604. }
  605.  
  606. // given an id, lookup the corresponding target
  607. // sRID - the ID of the desired topic (no default)
  608. // oDest - where to put the results of the lookup (no default)
  609. // bNoIncRefs - whether or not this lookup should count toward a reference (default is false)
  610. // sCurLang - the desired devlang for the lookup (default is the global devlang)
  611. // sOID - disambiguate the desired interface or object id (depending on the devlang) of the member (no default)
  612. //        if "auto" is specified, the primary/active interface of the current topic is used
  613. CLookup.prototype.LookupByRID = function(sRID, oDest, bNoIncRefs, sCurLang, sOID)
  614. {
  615.   if (!sCurLang)
  616.   {
  617.     sCurLang = this._oCtx._devlang;
  618.   }
  619.  
  620.   var oSrc = new CSimpleSrc(sRID, sCurLang);
  621.   if (sOID)
  622.   {
  623.     this.AddOID(oSrc, sOID);
  624.   }
  625.  
  626.   return this.Lookup(oSrc, oDest, bNoIncRefs);
  627. }
  628.  
  629. // adorn the source object with the requested iid or auto qualifier
  630. // this helps to resolve otherwise ambiguous xrefs
  631. CLookup.prototype.AddOID = function(oSrc, sOID)
  632. {
  633.   var sAttr = null, sCurLang = oSrc.devlang;
  634.   if (sOID == 'auto')
  635.   {
  636.     if (sAttr = gaMapAuto[sCurLang])
  637.     {
  638.       oSrc[sAttr] = 1;
  639.     }
  640.   }
  641.   else if (sAttr = gaMapAttr[sCurLang])
  642.   {
  643.     oSrc[sAttr] = sOID;
  644.   }
  645. }
  646.  
  647. // Lookup the target referenced by oNode.
  648. // Assumption here is that oNode is an XML DOM node that exposes a @rid.
  649. // CONSIDER: Support sKey parameter so that topic id can be
  650. // identified by some attr other than @rid.
  651. CLookup.prototype.LookupByNode = function(oNode, oDest, bNoIncRefs, sOID)
  652. {
  653.   if (!oNode)
  654.   {
  655.     this._error = "null node passed to LookupByNode";
  656.     return false;
  657.   }
  658.  
  659.   var sRID = oNode.getAttribute("rid");
  660.   if (!sRID)
  661.   {
  662.     this._error = "@rid not found on " + oNode.nodeName;
  663.     return false;
  664.   }
  665.  
  666.   var oObj = Node2Object(oNode);
  667.   if (!oObj)
  668.   {
  669.     return false;
  670.   }
  671.  
  672.   if (!oObj.devlang)
  673.   {
  674.     oObj.devlang = this._oCtx._devlang;
  675.   }
  676.  
  677.   // only attach the source node if it's an xref
  678.   if ("xref" == oNode.nodeName.toLowerCase())
  679.   {
  680.     oObj._srcNode = oNode;
  681.   }
  682.   else
  683.   {
  684.     // this param will never be passed in the typical xref case
  685.     // it will likely be passed in the iface/imembers case
  686.     if (sOID)
  687.     {
  688.       this.AddOID(oObj, sOID);
  689.     }
  690.   }
  691.  
  692.   return this.Lookup(oObj, oDest, bNoIncRefs);
  693.  
  694. }
  695.  
  696. // look for a target by name. This is slow (!!!) because
  697. // topics are not indexed by name.
  698. //at *** Rewritten for LuCache backend.
  699. // sName - the @name of the topic
  700. // oDest - js object used to store results
  701. // sCriteria - optional string used to help refine the query
  702. CLookup.prototype.LookUpByName = function(sName, oDest, sCriteria)
  703. {
  704.   var bOk = false;
  705.   var sTargXML = null;
  706.   var sTPath = this._oCtx._sDrive + this._oCtx.GetPathOf("targets");
  707.   var oTNodes = null;
  708.   var oTNode = null;
  709.   var oData = null;
  710.   var bLuCache = this._oCtx.CacheLookups();
  711.  
  712.   oData = this.EnsureData(bLuCache);
  713.   bLuCache = this._oCtx.CacheLookups();
  714.  
  715.   oDest.Init();
  716.  
  717.   if (sName)
  718.   {
  719.     oDest.SetCaption(sName);
  720.  
  721.     sCriteria = NormalizeCriteria(sCriteria);
  722.  
  723.     if (bLuCache && oData)
  724.     {
  725.       // Try to use the LuCache Lookup Cache.
  726.       try
  727.       {
  728.         // Call LuCache to lookup the name and get back the node-xml.
  729.         sTargXML = oData.LookupField(sName, "name", sTPath, sCriteria);
  730.       }
  731.       catch(e)
  732.       {
  733.         sTargXML = null;
  734.       }
  735.       if (sTargXML)
  736.       {
  737.         var oTDom = this._oCtx._oTDom;
  738.  
  739.         // Now use mini-dom node to load node-xml and get a node.
  740.         oTDom.async = false;
  741.         oTDom.loadXML(sTargXML);
  742.         oTNode = oTDom.documentElement;
  743.         if (oTNode)
  744.           bOk = true;
  745.         else
  746.           this._error = "cannot load node xml.";
  747.       }
  748.       else
  749.         this._error = "cannot locate " + sName;
  750.     }
  751.     else
  752.     {
  753.       // Try to use a loaded DOM for lookups.
  754.       if (bLuCache && !oData)
  755.         oData = this.EnsureData(false);
  756.       if (oData)
  757.       {
  758.         oTNodes = oData.selectNodes("/inetsdk:targets/targ[@name='" + sName + "']" + sCriteria);
  759.         if (oTNodes && oTNodes.length)
  760.         {
  761.           // BUGBUG: If we get back more than one, how do we disambiguate
  762.           // beyond sCriteria?
  763.           oTNode = oTNodes[0];
  764.           if (oTNode)
  765.             bOk = true;
  766.           else
  767.             this._error = "cannot locate " + sName;
  768.         }
  769.       }
  770.       else
  771.         this._error = "cannot create access to targets.";
  772.     }
  773.   }
  774.  
  775.   if (bOk)
  776.   {
  777.     var sRID = oTNode.getAttribute("id");
  778.     if (sRID)
  779.     {
  780.       var oSrc = new CSimpleSrc(sRID, this._oCtx._devlang);
  781.       var oCacheItem = this.RetrieveCachedItem(sRID, true);
  782.       if (oCacheItem)
  783.         bOk = this.BuildHREF(oSrc, oDest, oCacheItem);
  784.       else
  785.         bOk = false;
  786.     }
  787.     else
  788.     {
  789.       // wasted check. should never happen acc. DTD
  790.       this._error = "missing @rid";
  791.       bOk = false;
  792.     }
  793.   }
  794.  
  795.   return bOk;
  796. }
  797.  
  798. CLookup.prototype.BuildExtendedId = function(oSrc, oDest, oCacheItem){
  799.     var result = "";
  800.     var sDevLang = "";
  801.     
  802.     dp = oDest._ionodes.context.selectSingleNode(oDest._ionodes.expr);    // this is the deployment used.
  803.     
  804.     dp.getAttribute("hack") ? sDevLang = "scr" : sDevLang = dp.parentNode.getAttribute("value");
  805.     if (sDevLang == "none") sDevLang = "";
  806.     
  807.     // must make the extended id.  this id is derived from information about the link.
  808.     if(sDevLang == 'cpp' && dp.getAttribute("rid")){
  809.         result = result + dp.getAttribute("rid");
  810.     }
  811.     result = result + oSrc.rid;
  812.     
  813.     if (sDevLang != "") {
  814.         result = result + "_" + sDevLang;
  815.     }
  816.     
  817.     if(result){
  818.         oDest._extendedRid = result;
  819.     }
  820.  
  821. //  <META NAME="MS-HAID"><xsl:attribute name="CONTENT">
  822. //<xsl:choose>
  823. //<xsl:when test=".[/inetsdk:topic/metadata/applies/iface $and$ &var_devlang;='cpp']">
  824. //  <xsl:choose>
  825. //  <xsl:when test="/inetsdk:topic/metadata/applies/iface[@primary]"><xsl:value-of select="/inetsdk:topic/metadata/applies/iface[@primary]/@rid"/></xsl:when>
  826. //  <xsl:otherwise><xsl:value-of select="/inetsdk:topic/metadata/applies/iface/@rid"/></xsl:otherwise>
  827. //  </xsl:choose>
  828. //</xsl:when>
  829. //<xsl:when test=".[/inetsdk:topic/metadata/applies/object $and$ &var_devlang;='vb']">
  830. //  <xsl:choose>
  831. //  <xsl:when test="/inetsdk:topic/metadata/applies/object[@primary]"><xsl:value-of select="/inetsdk:topic/metadata/applies/object[@primary]/@rid"/></xsl:when>
  832. //  <xsl:otherwise><xsl:value-of select="/inetsdk:topic/metadata/applies/object/@rid"/></xsl:otherwise>
  833. //  </xsl:choose>
  834. //</xsl:when>
  835. ///</xsl:choose><xsl:value-of select="/inetsdk:topic/metadata/@id"/>&var_suffix;</xsl:attribute></META>
  836.  
  837.     return result;
  838. }
  839.  
  840. // use the metadata to fake a lookup
  841. // metadata is *mostly* polymorphic with a target node. No hrefs in metadata
  842. // This replaces GetMetaData
  843. // oNode - represents an xref when called from xref.xsl. Can be null
  844. // oDest - represents the destination object in which to cache results
  845. CLookup.prototype.LookupLocal = function(oNode, oDest)
  846. {
  847.   var oCtx = this._oCtx;
  848.   var oDoc = oCtx.GetDocument();
  849.   if (!oDoc)
  850.   {
  851.     this._error = "document reference unavailable in LookupLocal";
  852.     return false;
  853.   }
  854.  
  855.   var oMDNode = oDoc.selectSingleNode('/inetsdk:topic/metadata');
  856.   if (!oMDNode)
  857.   {
  858.     this._error = 'unable to locate metadata';
  859.     return false;
  860.   }
  861.  
  862.   var oSrcObj = null;
  863.   if (oNode)
  864.   {
  865.     oSrcObj = Node2Object(oNode);
  866.     if (!oSrcObj)
  867.     {
  868.       return false;
  869.     }
  870.  
  871.     if (!oSrcObj.devlang)
  872.     {
  873.       oSrcObj.devlang = oCtx.GetDevLang();
  874.     }
  875.   }
  876.   else
  877.   {
  878.     // no xref node was passed in, so cook up up
  879.     oSrcObj = new CSimpleSrc(oMDNode.getAttribute("id"), oCtx.GetDevLang());
  880.   }
  881.  
  882.   oSrcObj.self = true; // this is a self-reference
  883.  
  884.   oDest.Init();
  885.  
  886.   var oCacheItem = new CCacheItem(oMDNode, 0);
  887.  
  888.   oDest.SetItem(oSrcObj.rid, oCacheItem);
  889.  
  890.   // only attach the source node if it's an xref
  891.   if ("xref" == oNode.nodeName.toLowerCase())
  892.   {
  893.     oSrcObj._srcNode = oNode;
  894.   }
  895.  
  896.   if (!this.ExtractCaption(oSrcObj, oDest, oCacheItem))
  897.   {
  898.     return false;
  899.   }
  900.  
  901.   return true;
  902. }
  903.  
  904. // Lookup the xref referenced by oSrc.
  905. // bNoIncRefs  - if true, the reference count for the target is not incremented
  906. CLookup.prototype.Lookup = function(oSrc, oDest, bNoIncRefs)
  907. {
  908.   if (!oDest)
  909.   {
  910.     this._error = "Lookup: null destination data object";
  911.     return false;
  912.   }
  913.  
  914.   if (!oSrc)
  915.   {
  916.     this._error = "Lookup: null source data object";
  917.     return false;
  918.   }
  919.  
  920.   if (this._fBadDataSrc)
  921.   {
  922.     return false;
  923.   }
  924.  
  925.   this.ClearError();
  926.  
  927.   oDest.Init(); // clear out volatile data from the destination data object
  928.  
  929.   var sRID = oSrc.rid;
  930.   if (!sRID)
  931.   {
  932.     this._error = "@rid missing " + (oSrc._nodeName ? " on " + oSrc._nodeName : "");
  933.     return false;
  934.   }
  935.  
  936.   var oCacheItem = this.RetrieveCachedItem(sRID, bNoIncRefs);
  937.   if (!oCacheItem)
  938.   {
  939.     return false;
  940.   }
  941.  
  942.   oDest.SetItem(sRID, oCacheItem);
  943.  
  944.   if (!oSrc.devlang)
  945.   {
  946.     oSrc.devlang = this._oCtx._devlang;
  947.   }
  948.  
  949.   if (!this.ExtractCaption(oSrc, oDest, oCacheItem))
  950.   {
  951.     return false;
  952.   }
  953.  
  954.   if (!this.BuildHREF(oSrc, oDest, oCacheItem))
  955.   {
  956.     return false;
  957.   }
  958.  
  959.   if (!this.BuildExtendedId(oSrc, oDest, oCacheItem)){
  960.     return false;
  961.   }
  962.  
  963.   return true;
  964. }
  965.  
  966. CLookup.prototype.HasOverridingCaption = function(oSrc)
  967. {
  968.   var oRequest;
  969.   return (((oRequest = oSrc._srcNode) && oRequest.firstChild) ? true : false);
  970. }
  971.  
  972. CLookup.prototype.GetOverridingCaption = function(oSrc)
  973. {
  974.   var sCaption = "";
  975.   var oTLA = null;
  976.   var oRequest = oSrc._srcNode;
  977.  
  978.   if (oRequest)
  979.   {
  980.     //at: Add support for nested TLA in the overriding caption.
  981.   //Assumption is that if an xref contains a tla, the tla precedes any text
  982.     oTLA = oRequest.selectSingleNode("tla");
  983.     if (oTLA)
  984.     {
  985.       if (this.IsTLA(oTLA))
  986.         sCaption = this.GetTLA();
  987.       if (oRequest.text)
  988.       sCaption += " ";
  989.     }
  990.  
  991.     if (oRequest.text)
  992.     {
  993.       sCaption += oRequest.text;
  994.     }
  995.   }
  996.  
  997.   return sCaption;
  998. }
  999.  
  1000. /*
  1001.  Extract the caption from the data source
  1002.  
  1003.  oSrc - js object representing the source data requesting the link
  1004.  oCacheItem - js object representing the target node representing the link
  1005. */
  1006. CLookup.prototype.ExtractCaption = function(oSrc, oDest, oCacheItem)
  1007. {
  1008.   // BUGBUG: Neglects the possibility of markup descending from the xref (e.g. img)
  1009.   var oTNode = oCacheItem._targetNode;
  1010.   var sTPN = oCacheItem._pn;
  1011.   var bObj = (oSrc._nodeName && ("object" == oSrc._nodeName.toLowerCase()));
  1012.   var oDLNode;
  1013.  
  1014.   // first check if author has provided custom innerText for link
  1015.   // requires that the source XML node be attached to the source object
  1016.   if (this.HasOverridingCaption(oSrc))
  1017.   {
  1018.     oDest.SetCaption(this.GetOverridingCaption(oSrc));
  1019.     return true;
  1020.   }
  1021.  
  1022.   // Look for persistent name in targ
  1023.   // if: xref rid="..." type="pn"
  1024.   if (oSrc.type && ("pn" == oSrc.type))
  1025.   {
  1026.     if (!sTPN)
  1027.     {
  1028.       this._error = "target does not specify requested @pn.";
  1029.       return false;
  1030.     }
  1031.     else
  1032.     {
  1033.       oDest.SetCaption(sTPN);
  1034.     }
  1035.   }
  1036.   else
  1037.   {
  1038.     var sSubQuery;
  1039.  
  1040.     //markda: special processing if we are using targets V2.
  1041.     if ( this._oCtx.UseTargetsV2() && !oSrc.self )
  1042.     {
  1043.       sSubQuery = "/dp_info[@name]";
  1044.     }
  1045.     else
  1046.     {
  1047.       sSubQuery = "[@name]";
  1048.     }
  1049.  
  1050.     oDLNode = oTNode.selectSingleNode(gaDLangMap[(oSrc.self ? 'self' : 'ext')] + "[@value='" + oSrc.devlang + "']" + sSubQuery);
  1051.     if (oDLNode)
  1052.     {
  1053.       //markda: if there's a devlang-specific caption, use it.
  1054.       oDest.SetCaption(oDLNode.getAttribute("name"));
  1055.     }
  1056.     else
  1057.     {
  1058.       //at: Else if we're processing an object (eg, xrefs in AppliesTo),
  1059.       //at: then use the persistent name if the targ has one;
  1060.       //at: otherwise use the normal name.  Note that this logic
  1061.       //at: assumes that pn has the correct upper/lower case for
  1062.       //at: items like INPUT type=button.
  1063.       if (bObj && sTPN)
  1064.         oDest.SetCaption(sTPN);
  1065.       else
  1066.         oDest.SetCaption(oCacheItem._name);
  1067.     }
  1068.   } //markda
  1069.  
  1070.   // only attempt to extend the caption if the href is not at the targ level.
  1071.   // href on a targ indicates language neutrality or legacy HTM/ASP.
  1072.   if (!oCacheItem._href)
  1073.   {
  1074.     var sPageType = oCacheItem._type, sDevLang = oSrc.devlang;
  1075.  
  1076.     if ((oSrc.type != 'pn') && (sDevLang == "cpp") && (sPageType == "method" || sPageType == "property" || sPageType == "collection" || sPageType == "event"))
  1077.     {
  1078.       // Look for an iface/object prefix
  1079.       if (!this.GetExtendedCaption(oSrc, oDest, oCacheItem))
  1080.       {
  1081.         return false;
  1082.       }
  1083.     }
  1084.   }
  1085.  
  1086.   return true;
  1087. }
  1088.  
  1089. CLookup.prototype.GetExtendedCaption = function(oSrc, oDest, oCacheItem)
  1090. {
  1091.   // BUGBUG: if this is a property, prepend the put/get if C++??
  1092.   var oNodes = null;
  1093.   if (!(oNodes = this.EnsureIONodes(oSrc, oDest, oCacheItem)))
  1094.   {
  1095.     return false;
  1096.   }
  1097.   else if (oNodes.length == 1)
  1098.   {
  1099.     return this.GatherTargetData(oSrc, oDest, oNodes[0]);
  1100.   }
  1101.   else // (oNodes.length > 1)
  1102.   {
  1103.     if (oSrc.self) // the @primary check only works in the self-reference case
  1104.     {
  1105.       var sIOQuery = "applies/" + gaMapLang2SubNode[oSrc.devlang] + "[@primary]";
  1106.       var oNode = oCacheItem._targetNode.selectSingleNode(sIOQuery);
  1107.       if (oNode)
  1108.       {
  1109.         return this.GatherTargetData(oSrc, oDest, oNode);
  1110.       }
  1111.       else
  1112.       {
  1113.         this.GatherTargetData(oSrc, oDest, oNodes[0]);
  1114.         return true;
  1115.       }
  1116.     }
  1117.     else
  1118.     {
  1119.       this._error = "ambiguous xref; must specify @iid, @oid, or @primary.";
  1120.       return false;
  1121.     }
  1122.   }
  1123.  
  1124. }
  1125.  
  1126. CLookup.prototype.GatherTargetData = function(oSrc, oDest, oNode)
  1127. {
  1128.   var sIOCaption = oNode.getAttribute("name");
  1129.   if (sIOCaption)
  1130.   {
  1131.     oDest.SetCaption(sIOCaption);
  1132.   }
  1133.   else
  1134.   {
  1135.   //markda: attribute optional for targets V2
  1136.   var sRID;
  1137.     if ( sRID = oNode.getAttribute("rid") )
  1138.     {
  1139.   //markda: end
  1140.       // The following code executes when the target node (oNode) is actually part of the topic/metadata (self-reference case)
  1141.       // In that case we need to do a lookup because the redundant data is not stored there
  1142.       var sRID = oNode.getAttribute("rid");
  1143.       var oIONode = this.RetrieveTarget(sRID);
  1144.       if (!oIONode)
  1145.       {
  1146.         // this._error = gaMapLang2SubNode[oSrc.devlang] + "'" + sRID + "' not found."
  1147.         return false;
  1148.       }
  1149.  
  1150.       // pre-pend the appropriate scope operator
  1151.       oDest.SetCaption(oIONode.getAttribute("name") + gaMapScope[oSrc.devlang] + oDest.GetCaption());
  1152.     }
  1153.     //markda: if using targets V2, use targ[@name] if no dp_info[@name]
  1154.     else
  1155.   {
  1156.     if ( this._oCtx.UseTargetsV2()
  1157.            && (sIOCaption = oNode.parentNode.parentNode.getAttribute("name")) )
  1158.       {
  1159.         oDest.SetCaption(sIOCaption);
  1160.       }
  1161.     }
  1162.   }
  1163.   //markda: end
  1164.  
  1165.   return true;
  1166. }
  1167.  
  1168. // Build a query to drill into the target, and return the collection of nodes that qualify
  1169. CLookup.prototype.EnsureIONodes = function(oSrc, oDest, oCacheItem)
  1170. {
  1171.   // self base query: applies/iface[@rid=''] or applies/object[@rid='']
  1172.   // extern base query: dlang[@value='cpp']/dp_iface or dlang[@value='vb']/dp_object
  1173.   //markda: for targets V2: dlang[@value='cpp']/dp_info or dlang[@value='vb']/dp_info
  1174.  
  1175.   var sDevLang = oSrc.devlang;
  1176.  
  1177.   //markda: with targets V2, all devlangs have subnodes
  1178.   if ( ! this._oCtx.UseTargetsV2() )
  1179.   {
  1180.   //markda: end
  1181.     // no need to check for iface/object for this devlang
  1182.     if (typeof(gaMapLang2SubNode[sDevLang]) == 'undefined')
  1183.     {
  1184.       this._error = "devlang '" + sDevLang + "' doesn't support subnodes.";
  1185.       return null;
  1186.     }
  1187.   } //markda
  1188.  
  1189.   if (oDest._ionodes)
  1190.   {
  1191.     return oDest._ionodes;
  1192.   }
  1193.  
  1194.   var sIOQuery;
  1195.  
  1196.   if (oSrc.self)
  1197.   {
  1198.     sIOQuery = "applies/" + gaMapLang2SubNode[sDevLang];
  1199.   }
  1200.   else
  1201.   {
  1202.     //markda: determine if we are using targets V1 or V2
  1203.     if ( this._oCtx.UseTargetsV2() )
  1204.     {
  1205.     if ( sDevLang == "" )
  1206.         sDevLang = "none";
  1207.       sIOQuery = "dlang[@value='" + sDevLang + "']/dp_info";
  1208.     }
  1209.     else //markda: end
  1210.       sIOQuery = "dlang[@value='" + sDevLang + "']/dp_" + gaMapLang2SubNode[sDevLang];
  1211.   }
  1212.  
  1213.   // check if the author has specified an @iid or @oid on the xref
  1214.   if (typeof(gaMapAttr[sDevLang]) != 'undefined'  && oSrc)
  1215.   {
  1216.     // attempt to qualify the query so as to avoid an ambiguous xref
  1217.  
  1218.     var sAttr, sVal, sIORID = null;
  1219.     // use the @iid or @oid if one has been specified
  1220.     if ( (sAttr = gaMapAttr[sDevLang]) && (sVal = oSrc[sAttr]) )
  1221.     {
  1222.       sIORID = sVal;
  1223.     }
  1224.     // otherwise attempt to autoresolve if the author gave us permission
  1225.     else if ( (sAttr = gaMapAuto[sDevLang]) && oSrc[sAttr] )
  1226.     {
  1227.  
  1228.       var oIFaces;
  1229.       var sPageType = GetPageType(); // get the type of the current doc
  1230.       if (sPageType && (sPageType == "iface"))
  1231.       {
  1232.         var oIFaceID = ownerDocument.selectSingleNode("/inetsdk:topic/metadata/@id");
  1233.         if (!oIFaceID)
  1234.         {
  1235.           this._error = "interface page doesn't specify an id";
  1236.           return false;
  1237.         }
  1238.         else
  1239.         {
  1240.           sIORID = oIFaceID.value;
  1241.         }
  1242.       }
  1243.       // use the primary iid of the current topic
  1244.       else if ( (oIFaces = ownerDocument.selectNodes("/inetsdk:topic/metadata/applies/" + gaMapLang2SubNode[sDevLang] + "[@rid $and$ @primary]") ) && oIFaces.length == 1)
  1245.       {
  1246.         sIORID = oIFaces[0].getAttribute("rid");
  1247.       }
  1248.       else if ( (oIFaces = ownerDocument.selectNodes("/inetsdk:topic/metadata/applies/" + gaMapLang2SubNode[sDevLang] + "[@rid]")) && oIFaces.length == 1)
  1249.       {
  1250.         sIORID = oIFaces[0].getAttribute("rid");
  1251.       }
  1252.     }
  1253.  
  1254.     if (sIORID)
  1255.     {
  1256.       sIOQuery += "[@rid='" + sIORID + "']";
  1257.     }
  1258.   }
  1259.  
  1260.   // query for the iface/object nodes below the target
  1261.   var oNodes = oCacheItem._targetNode.selectNodes(sIOQuery);
  1262.   if (!oNodes || !oNodes.length)
  1263.   {
  1264.     //markda: attempt to get generic target
  1265.     if ( this._oCtx.UseTargetsV2() )
  1266.     {
  1267.       oNodes = oCacheItem._targetNode.selectNodes( "dlang/dp_info" );
  1268.       if (!oNodes || !oNodes.length)
  1269.       {
  1270.         this._error = "query failure after retry! [" + sIOQuery + "]";
  1271.         return null;
  1272.       }
  1273.     }
  1274.     else
  1275.     {  //markda: end
  1276.       this._error = "query failure! [" + sIOQuery + "]";
  1277.       return null;
  1278.     } //markda
  1279.   }
  1280.  
  1281.   return (oDest._ionodes = oNodes);
  1282. }
  1283.  
  1284. CLookup.prototype.GetError = function()
  1285. {
  1286.   return this._error;
  1287. }
  1288.  
  1289. CLookup.prototype.IsType = function(o, oDest, sCompareType)
  1290. {
  1291.   if (!this.LookupByNode(o, oDest, true))
  1292.   {
  1293.     return false;
  1294.   }
  1295.  
  1296.   var sType = oDest.GetType();
  1297.   return (sType == sCompareType ? true : false);
  1298. }
  1299.  
  1300. // load the data source used to perform lookups
  1301. //at *** Rewritten for LuCache.
  1302. CLookup.prototype.EnsureData = function(bLuCache)
  1303. {
  1304.   var oData = null;
  1305.   var sError = "";
  1306.  
  1307.   // BUGBUG: What if object is created but data can't be loaded
  1308.   if (typeof(this._data) == 'undefined')
  1309.   {
  1310.     // Determine if LuCache is out there.
  1311.     try
  1312.     {
  1313.       oData = new ActiveXObject("LuCache.Lookup");
  1314.     }
  1315.     catch(e)
  1316.     {
  1317.       sError = "cannot instantiate LuCache. " + e.description;
  1318.     }
  1319.  
  1320.     if (bLuCache)
  1321.     {
  1322.       // Try to use the LuCache fast lookup cache.
  1323.       if (oData)
  1324.         this._data = oData;
  1325.       else
  1326.       {
  1327.         this._error = sError;
  1328.         this._oCtx.NoCacheLookups();
  1329.       }
  1330.     }
  1331.  
  1332.     if (!this._data)
  1333.     {
  1334.       // Try to use an XML DOM.
  1335.       try
  1336.       {
  1337.         this._data = new ActiveXObject("MSXML.DOMDocument");
  1338.       }
  1339.       catch(e)
  1340.       {
  1341.         this._error = "cannot instantiate MSXML. " + e.description;
  1342.         return null;
  1343.       }
  1344.  
  1345.       this._data.async = false;
  1346.       this._data.load(this._oCtx.GetPathOf("targets"));
  1347.       var oPErr = this._data.parseError;
  1348.       if (oPErr.errorCode != 0)
  1349.       {
  1350.         this._error = oPErr.url + "(" + oPErr.line + "): Targets lookup error: " + oPErr.reason.replace(/[\n\r]/g,"");
  1351.         this._fBadDataSrc = true;
  1352.         return null;
  1353.       }
  1354.     }
  1355.   }
  1356.   else if (this._fBadDataSrc)
  1357.   {
  1358.     return null;
  1359.   }
  1360.  
  1361.   //at+ Add code here to check for parse error during load of targets.xml.
  1362.   //at+ This would require a new method, ILookup::GetError.
  1363.  
  1364.   return this._data;
  1365. }
  1366.  
  1367. // Ensure topic info (topinfo.xml) is available for retrieval. //at
  1368. CLookup.prototype.EnsureTIData = function(bLuCache)
  1369. {
  1370.   var oData = null;
  1371.   var sError = "";
  1372.  
  1373.   if (typeof(this._tidata) == 'undefined')
  1374.   {
  1375.     // Determine if LuCache is out there.
  1376.     try
  1377.     {
  1378.       oData = new ActiveXObject("LuCache.Lookup");
  1379.     }
  1380.     catch(e)
  1381.     {
  1382.       sError = "cannot instantiate LuCache. " + e.description;
  1383.     }
  1384.  
  1385.     if (bLuCache)
  1386.     {
  1387.       // Try to use the LuCache fast lookup cache.
  1388.       if (oData)
  1389.         this._tidata = oData;
  1390.       else
  1391.       {
  1392.         this._error = sError;
  1393.         this._oCtx.NoCacheLookups();
  1394.       }
  1395.     }
  1396.  
  1397.     if (!this._tidata)
  1398.     {
  1399.       // Try to use an XML DOM.
  1400.       try
  1401.       {
  1402.         this._tidata = new ActiveXObject("MSXML.DOMDocument");
  1403.       }
  1404.       catch(e)
  1405.       {
  1406.         this._error = "cannot instantiate MSXML. " + e.description;
  1407.         return null;
  1408.       }
  1409.  
  1410.       this._tidata.async = false;
  1411.       this._tidata.load(this._oCtx.GetPathOf("topinfo"));
  1412.       var oPErr = this._tidata.parseError;
  1413.       if (oPErr.errorCode != 0)
  1414.       {
  1415.         this._error = oPErr.url + "(" + oPErr.line + "): Topic Info lookup error: " + oPErr.reason.replace(/[\n\r]/g,"");
  1416.         this._fBadDataSrc = true;
  1417.         return null;
  1418.       }
  1419.     }
  1420.   }
  1421.   else if (this._fBadDataSrc)
  1422.   {
  1423.     return null;
  1424.   }
  1425.  
  1426.   return this._tidata;
  1427. }
  1428.  
  1429. // Ensure Acronyms data (acronyms.xml) is available for retrieval. //at
  1430. CLookup.prototype.EnsureAcData = function(bLuCache)
  1431. {
  1432.   var oData = null;
  1433.   var sError = "";
  1434.  
  1435.   if (typeof(this._acdata) == 'undefined')
  1436.   {
  1437.     // Determine if LuCache is out there.
  1438.     try
  1439.     {
  1440.       oData = new ActiveXObject("LuCache.Lookup");
  1441.     }
  1442.     catch(e)
  1443.     {
  1444.       sError = "cannot instantiate LuCache. " + e.description;
  1445.     }
  1446.  
  1447.     if (bLuCache)
  1448.     {
  1449.       // Try to use the LuCache fast lookup cache.
  1450.       if (oData)
  1451.         this._acdata = oData;
  1452.       else
  1453.       {
  1454.         this._error = sError;
  1455.         this._oCtx.NoCacheLookups();
  1456.       }
  1457.     }
  1458.  
  1459.     if (!this._acdata)
  1460.     {
  1461.       // Try to use an XML DOM.
  1462.       try
  1463.       {
  1464.         this._acdata = new ActiveXObject("MSXML.DOMDocument");
  1465.       }
  1466.       catch(e)
  1467.       {
  1468.         this._error = "cannot instantiate MSXML. " + e.description;
  1469.         return null;
  1470.       }
  1471.  
  1472.       this._acdata.async = false;
  1473.       this._acdata.load(this._oCtx.GetPathOf("acronyms"));
  1474.       var oPErr = this._acdata.parseError;
  1475.       if (oPErr.errorCode != 0)
  1476.       {
  1477.         this._error = oPErr.url + "(" + oPErr.line + "): TLA lookup error: " + oPErr.reason.replace(/[\n\r]/g,"");
  1478.         this._fBadDataSrc = true;
  1479.         return null;
  1480.       }
  1481.     }
  1482.   }
  1483.   else if (this._fBadDataSrc)
  1484.   {
  1485.     return null;
  1486.   }
  1487.  
  1488.   return this._acdata;
  1489. }
  1490.  
  1491. CLookup.prototype.BuildHREF = function(oSrc, oDest, oCacheItem)
  1492. {
  1493.   var oTNode = oCacheItem._targetNode;
  1494.   var sMedia = this._oCtx._media;
  1495.   var sChm = oTNode.getAttribute("chm");
  1496.   var sTargHREF = "";
  1497.   var bHTTP = false;
  1498.  
  1499.   oDest._leave = "";
  1500.  
  1501.   oDest._hxslink = "";
  1502.   /* This section moved down (in modified form) to line 1533
  1503.   if (sMedia && sChm == "other")
  1504.   {
  1505.     switch (sMedia)
  1506.     {
  1507.       case "chm":
  1508.         // generate an ALINK if we're in CHM mode and are
  1509.         // linking to something in another CHM
  1510.         oDest._alink = oSrc.rid;
  1511.         // javascript: doesn't like ids that contain colons. Convert to "__"
  1512.         oDest._alinkproxy = oSrc.rid.replace(":","__");
  1513.         oDest.SetHREF("JavaScript:" + oDest._alinkproxy + ".Click()");
  1514.         oDest._leave = "chm";
  1515.         return true;
  1516.         break;
  1517.       case "hxs":
  1518.         //at: Assemble the Havana (Hxs) link if we're in CHM mode and are
  1519.         // linking to something in another CHM
  1520.         oDest._hxslink = '<MSHelp:link keywords="' + oSrc.rid + '" TABINDEX="0">' + oDest._caption + '</MSHelp:link>';
  1521.         oDest._leave = "chm";
  1522.         return true;
  1523.         break;
  1524.       default:
  1525.         break;
  1526.     }
  1527.   }
  1528.   */
  1529.  
  1530.   if (!this.ExtractHREF(oSrc, oDest, oCacheItem))
  1531.   {
  1532.     return false;
  1533.   }
  1534.  
  1535.   sTargHREF = oDest.GetHREF();
  1536.   bHTTP = /^http:\/\//i.test(sTargHREF);
  1537.  
  1538.   if (sMedia)
  1539.   {
  1540.     switch (sMedia)
  1541.     {
  1542.       case "chm":
  1543.         if (sChm == "other")
  1544.         {
  1545.           // generate an ALINK if we're in CHM mode and are
  1546.           // linking to something in another CHM
  1547.           oDest._alink = oSrc.rid;
  1548.           // javascript: doesn't like ids that contain colons. Convert to "__"
  1549.           oDest._alinkproxy = oSrc.rid.replace(":","__");
  1550.           oDest.SetHREF("JavaScript:" + oDest._alinkproxy + ".Click()");
  1551.           oDest._leave = "chm";
  1552.           return true;
  1553.         }
  1554.         break;
  1555.       case "hxs":
  1556.         if (bHTTP)
  1557.         {
  1558.           oDest._leave = "ms";
  1559.         }
  1560.         else
  1561.         {
  1562.             // peterril:  code that generates the mshelp:link will be defered until
  1563.             //              render time.
  1564.             oDest._hxslink = "useless";        // just a placeholding to indicate that this
  1565.                                             // is an hxs link.
  1566.             return true;
  1567.         }
  1568.         break;
  1569.       default:
  1570.         break;
  1571.     }
  1572.   }
  1573.  
  1574.   // Prevent recursion. if this is a self-reference we're done.
  1575.   // Don't calculate a path relative to yourself!!
  1576.   if (goTD.IsSelf(oSrc.rid))
  1577.   {
  1578.     return true;
  1579.   }
  1580.  
  1581.   if (bHTTP)
  1582.   {
  1583.     if (sMedia && (sMedia == 'chm') && sChm && (sChm == 'other'))
  1584.     {  // Linking to another CHM
  1585.       oDest._leave = "chm";
  1586.       return true;
  1587.     }
  1588.     else if (sMedia && (sMedia == 'chm') && !sChm)
  1589.     {  // Linking to another CHM
  1590.       oDest._leave = "ms";
  1591.       return true;
  1592.     }
  1593.     else
  1594.     {
  1595.       // Search list of Microsoft sites
  1596.       var bFound = false;
  1597.       var len = gaMSSiteREs.length;
  1598.       for ( var i=0; i<len; i++ )
  1599.       {
  1600.         if ( gaMSSiteREs[i].test(sTargHREF) )
  1601.         { // Linking to a non-MS site
  1602.           bFound = true;
  1603.           break;
  1604.         }
  1605.       }
  1606.       if ( ! bFound )
  1607.       { // Linking to a non-MS site
  1608.         oDest._leave = "ms";
  1609.         return true;
  1610.       }
  1611.     }
  1612.   }
  1613.  
  1614.   if (!goTD.Ensure())
  1615.   {
  1616.     this._error = goTD.GetError();
  1617.     return false;
  1618.   }
  1619.  
  1620.  
  1621.   if (sMedia && (sMedia == 'chm'))
  1622.   {
  1623.     var sHREF;
  1624.     // BUGBUG: htm extension is hard-coded in the CHM case.
  1625.     sHREF = MakeRelative(goTD.GetHREF(), oDest.GetHREF());
  1626.     if (!sHREF)
  1627.     {
  1628.       this._error = "VROOT2Relative failure.";
  1629.       return false;
  1630.     }
  1631.     else
  1632.     {
  1633.       //Only change the target path if its extension is in the map.
  1634.       var sExt = JustExt(sHREF);
  1635.       if (sExt)
  1636.       {
  1637.         var sNewExt = gaExtMap[sExt];
  1638.         if (sNewExt)
  1639.         {
  1640.           sHREF = ChangeExt(sHREF, sNewExt);
  1641.         }
  1642.       }
  1643.  
  1644.       oDest.SetHREF(sHREF);
  1645.  
  1646.       return true;
  1647.     }
  1648.   }
  1649.  
  1650.   return true;
  1651.  
  1652. }
  1653.  
  1654. // extract the href from the target
  1655. CLookup.prototype.ExtractHREF = function(oSrc, oDest, oCacheItem)
  1656. {
  1657.   var oTNode = oCacheItem._targetNode;
  1658.   var sDevLang = oSrc.devlang;
  1659.   var sPageType = oCacheItem._type;
  1660.  
  1661.   var oHREF = null, oNodes = null, sHREF = null;
  1662.  
  1663.   //markda: special procesing if we are using targets V2
  1664.   if ( this._oCtx.UseTargetsV2() )
  1665.   {
  1666.     if ( oNodes = this.EnsureIONodes( oSrc, oDest, oCacheItem ) )
  1667.     {
  1668.       if (oNodes.length == 1)
  1669.       {
  1670.         sHREF = oNodes[0].getAttribute("href");
  1671.         if ( sHREF )
  1672.         {
  1673.           oDest.SetHREF( sHREF );
  1674.         }
  1675.         else
  1676.         {
  1677.           this._error = "@href missing from target subnode.";
  1678.           return false;
  1679.         }
  1680.       }
  1681.       else
  1682.       {
  1683.         this._error = "ambiguous xref; must specify @iid, @oid, or @primary.";
  1684.         return false;
  1685.       }
  1686.     }
  1687.     else
  1688.     {
  1689.       return false;
  1690.     }
  1691.   }
  1692.   else
  1693.   {
  1694.   //markda: end
  1695.     if (sDevLang == "") // generic topic
  1696.     {
  1697.       if (!(oDest.SetHREF(oTNode.getAttribute("href"))))
  1698.       {
  1699.         this._error = "@href missing on generic topic targ node.";
  1700.         return false;
  1701.       }
  1702.     }
  1703.  
  1704.     // check for @href on dlang <dlang value="scr" href="..."
  1705.     else if (oHREF = oTNode.selectSingleNode("dlang[@value='" + sDevLang + "']/@href"))
  1706.     {
  1707.       oDest.SetHREF(oHREF.value);
  1708.     }
  1709.     // check @href on dlang/dp_iface || dlang/dp_object
  1710.     else if (oNodes = this.EnsureIONodes(oSrc, oDest, oCacheItem))
  1711.     {
  1712.       if (oNodes.length == 1)
  1713.       {
  1714.         if (!oDest.SetHREF(oNodes(0).getAttribute("href")))
  1715.         {
  1716.           this._error = "@href missing from target subnode.";
  1717.           return false;
  1718.         }
  1719.       }
  1720.       else
  1721.       {
  1722.         this._error = "ambiguous xref; must specify @iid, @oid, or @primary.";
  1723.         return false;
  1724.       }
  1725.     }
  1726.     // check for href on targ first
  1727.     else if (sHREF = oTNode.getAttribute("href"))
  1728.     {
  1729.        // href directly on the targ
  1730.        oDest.SetHREF(sHREF)
  1731.     }
  1732.     else
  1733.     {
  1734.       this._error = "href missing on target node";
  1735.       return false;
  1736.     }
  1737.   }
  1738.  
  1739.   if (!this.CheckFragment(oSrc, oDest, oCacheItem))
  1740.   {
  1741.     //at: Enforce authoring of valid fids.
  1742.     this._error = "unknown fragment: fid='" + oSrc.fid + "'";
  1743.     return false;
  1744.   }
  1745.  
  1746.   return true;
  1747. }
  1748.  
  1749. CLookup.prototype.CheckFragment = function(oSrc, oDest, oCacheItem)
  1750. {
  1751.   if (!oSrc)
  1752.   {
  1753.     return true;
  1754.   }
  1755.  
  1756.   var sFid = oSrc.fid;
  1757.   if (sFid)
  1758.   {
  1759.     var oTNode = oCacheItem._targetNode;
  1760.  
  1761.     var oFrag = oTNode.selectSingleNode("frag[@id='" + sFid + "'][@caption]");
  1762.     if (oFrag)
  1763.     {
  1764.       oDest.SetHREF(oDest.GetHREF() + "#" + sFid);
  1765.       if (!this.HasOverridingCaption(oSrc))
  1766.       {
  1767.         oDest.SetCaption(oFrag.getAttribute("caption"));
  1768.       }
  1769.     }
  1770.     else
  1771.     {
  1772.       // BUGBUG: We can be a little more tolerant here since the page physically exists.
  1773.       //oDest._error = "Invalid fragment specifier '" + sFid + "'.";
  1774.       //at: oDest.SetHREF(oDest.GetHREF() + "#unknown_fragment");
  1775.       return false;
  1776.     }
  1777.   }
  1778.  
  1779.   return true;
  1780. }
  1781.  
  1782. // if the specified node refers to a namespace, cache the name
  1783. CLookup.prototype.IsNameSpaceRef = function(oSrcNode, sKey)
  1784. {
  1785.   this._nsinfo = new Object();
  1786.  
  1787.   if (!sKey)
  1788.   {
  1789.     sKey = "rid";
  1790.   }
  1791.  
  1792.   var sRID = oSrcNode.getAttribute(sKey);
  1793.   if (!sRID)
  1794.   {
  1795.     this._error = "unable to retrieve " + sKey + " from node."
  1796.     return false;
  1797.   }
  1798.  
  1799.   var oCacheItem = this.RetrieveCachedItem(sRID, true);
  1800.   if (!oCacheItem)
  1801.   {
  1802.     return false;
  1803.   }
  1804.  
  1805.   var oTNode = oCacheItem._targetNode;
  1806.   if (!oTNode)
  1807.   {
  1808.     return false;
  1809.   }
  1810.  
  1811.   var sType = oTNode.getAttribute("type");
  1812.   if (sType && sType == "namespace")
  1813.   {
  1814.     this._nsinfo["key"] = sRID;
  1815.     this._nsinfo["name"] = oTNode.getAttribute("name");
  1816.     return true;
  1817.   }
  1818.  
  1819.   return false;
  1820. }
  1821.  
  1822. // assuming the namespace has already been retrieved, return the specified attribute. only "name" is currently supported
  1823. CLookup.prototype.GetNameSpaceInfo = function(o, sAttr)
  1824. {
  1825.   // should never happen if IsNameSpaceRef is called first and return value is checked
  1826.   if (null == this._nsinfo || null == this._nsinfo[sAttr])
  1827.   {
  1828.     return "";
  1829.   }
  1830.  
  1831.   return this._nsinfo[sAttr];
  1832. }
  1833.  
  1834.  
  1835. // returns true if the ref topic applies to at least one object that has a persistent representation
  1836. function AppliesToPersistentHTMLObject()
  1837. {
  1838.   // peterril: commented out this condition because DHTML is defined for only the core DOM.  That means that
  1839.   //           all the other scripting events do not have this tech value.
  1840.   // BUGBUG: Only show this for HTML objects?
  1841.   //if (!ownerDocument.selectSingleNode("/inetsdk:topic/metadata/tech[@value='dhtml']"))
  1842.   //{
  1843.   //  return false;
  1844.   //}
  1845.  
  1846.   var oObjects = ownerDocument.selectNodes("/inetsdk:topic/metadata/applies/object/@rid");
  1847.   if (!oObjects || 0 == oObjects.length)
  1848.   {
  1849.     return false;
  1850.   }
  1851.  
  1852.   for (var i = 0; i < oObjects.length; i++)
  1853.   {
  1854.     var oTNode = goLookup.RetrieveTarget(oObjects[i].value);
  1855.     if (!oTNode)
  1856.     {
  1857.       continue;
  1858.     }
  1859.     else if (oTNode.getAttribute("pn")) // BUGBUG: Assumes XML for target data
  1860.     {
  1861.       return true;
  1862.     }
  1863.   }
  1864.  
  1865.   return false;
  1866. }
  1867.  
  1868. // Retrieve the type of the current topic
  1869. function GetPageType()
  1870. {
  1871.   var oTypeAttr;
  1872.   if (oTypeAttr = ownerDocument.selectSingleNode("/inetsdk:topic/metadata/@type"))
  1873.   {
  1874.     return (oTypeAttr.value);
  1875.   }
  1876.   else
  1877.   {
  1878.     return null;
  1879.   }
  1880. }
  1881.  
  1882. // Does sRID match the id of the current topic
  1883. function IsSelfReference(sRID)
  1884. {
  1885.   return ( (sRID == null || sRID == ownerDocument.selectSingleNode("/inetsdk:topic/metadata/@id").value) ? true : false);
  1886. }
  1887.  
  1888. // map the attributes of an XML DOM Node to the properties of a JScript object
  1889. function Node2Object(oNode, oObj, sPrefix)
  1890. {
  1891.   if (!oNode)
  1892.   {
  1893.     return null;
  1894.   }
  1895.  
  1896.   if (!oObj)
  1897.   {
  1898.     oObj = new Object();
  1899.   }
  1900.  
  1901.   var oAttrs = oNode.attributes;
  1902.   for (var i = 0; i < oAttrs.length; i++)
  1903.   {
  1904.     var oAttr = oAttrs(i)
  1905.     oObj[(sPrefix ? sPrefix : "") + oAttr.name] = oAttr.value;
  1906.   }
  1907.  
  1908.   oObj._nodeName = oNode.nodeName;
  1909.  
  1910.   return oObj;
  1911. }
  1912.  
  1913. // Ensure that the criteria string contains single quotes and is surrounded by square brackets
  1914. function NormalizeCriteria(sCriteria)
  1915. {
  1916.   if (typeof(sCriteria) != 'string')
  1917.   {
  1918.     return "";
  1919.   }
  1920.  
  1921.   sCriteria = sCriteria.replace(/"/g, "'");
  1922.   if (!/^\[/.test(sCriteria))
  1923.   {
  1924.     sCriteria = "[" + sCriteria;
  1925.   }
  1926.  
  1927.   if (!/\]$/.test(sCriteria))
  1928.   {
  1929.     sCriteria += "]";
  1930.   }
  1931.  
  1932.   return sCriteria;
  1933. }
  1934.  
  1935.  
  1936. /* XREF code END */
  1937. ]]>
  1938.